{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "InverseNumber=LibraryFunctionLoad[\"/home/yangyongkang/文档/C-CPP_WolframLibrary_Example/Inversions.so\",\"InverseNumber\",{{Integer,1}},\"UTF8String\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div><img alt=\"Output\" src=\"\"></div>"
      ],
      "text/plain": [
       "LibraryFunction[<>, Naive_InverseNumber, {{Integer, 1}}, Integer]"
      ]
     },
     "execution_count": 2,
     "metadata": {
      "text/html": [],
      "text/plain": []
     },
     "output_type": "execute_result"
    }
   ],
   "source": [
    "NaiveInverseNumber=LibraryFunctionLoad[\"/home/yangyongkang/文档/C-CPP_WolframLibrary_Example/Naive_InverseNumber.so\",\"Naive_InverseNumber\",{{Integer,1}},Integer]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [],
   "source": [
    "time1=(RepeatedTiming[NaiveInverseNumber[RandomSample@Range[10*#,1,-1]];]&/@Range@50)[[All,1]];"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [],
   "source": [
    "time2=(RepeatedTiming[InverseNumber[RandomSample@Range[10*#,1,-1]];]&/@Range@50)[[All,1]];"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div><img alt=\"Output\" src=\"\"></div>"
      ],
      "text/plain": [
       "                                                            1\n",
       "Legended[-Graphics-, Placed[LineLegend[{Directive[PointSize[--], \n",
       "                                                            72\n",
       " \n",
       ">       RGBColor[0.368417, 0.506779, 0.709798], AbsoluteThickness[1.6]], \n",
       " \n",
       "                           1\n",
       ">      Directive[PointSize[--], RGBColor[0.880722, 0.611041, 0.142051], \n",
       "                           72\n",
       " \n",
       ">       AbsoluteThickness[1.6]]}, {Naive, Merge}, \n",
       " \n",
       ">     LegendMarkers -> {{False, Automatic}, {False, Automatic}}, Joined -> {True, True}, \n",
       " \n",
       ">     LabelStyle -> {}, LegendLayout -> Column], After, Identity]]"
      ]
     },
     "execution_count": 29,
     "metadata": {
      "text/html": [],
      "text/plain": []
     },
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ListLinePlot[{time1,time2},PlotLegends->{\"Naive\",\"Merge\"}]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div><img alt=\"Output\" src=\"\"></div>"
      ],
      "text/plain": [
       "{0.434453, Null}"
      ]
     },
     "execution_count": 50,
     "metadata": {
      "text/html": [],
      "text/plain": []
     },
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Do[Table[InverseNumber@i,{i,Permutations[Range@2,{2}]}],100000]//AbsoluteTiming"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div><img alt=\"Output\" src=\"\"></div>"
      ],
      "text/plain": [
       "{0.364133, Null}"
      ]
     },
     "execution_count": 51,
     "metadata": {
      "text/html": [],
      "text/plain": []
     },
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Do[Table[NaiveInverseNumber@i,{i,Permutations[Range@2,{2}]}],100000];//AbsoluteTiming"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Wolfram Language 12.1",
   "language": "Wolfram Language",
   "name": "wolframlanguage12.1"
  },
  "language_info": {
   "codemirror_mode": "mathematica",
   "file_extension": ".m",
   "mimetype": "application/vnd.wolfram.m",
   "name": "Wolfram Language",
   "pygments_lexer": "mathematica",
   "version": "12.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
